package com.cy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨域配置
 */
@Configuration
public class WebConfig {
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**") // 配置允许的路径
                        .allowedOrigins("http://localhost:5173") // 配置允许的前端地址
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD") // 配置允许的方法
                        .allowCredentials(true); // 允许发送Cookie
            }
        };
    }
}
